'''
Author: thinktanker thinktanker@163.com
Date: 2024-02-01 17:22:44
LastEditors: duliang thinktanker@163.com
LastEditTime: 2024-02-01 23:18:18
FilePath: \control-net\test.py
Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
'''
import re


def shortcontent(str):
    '''
    优化发送字符串，可减少一半
    '''
    resub = re.sub(r'[\u4e00-\u9fa5]', r'', str)
    # print(len(resub))
    resub = re.sub(r'1a', r'Ia', str)
    # print(len(resub))
    resub = re.sub(r'35k|6016|631|621|622|6111|6122|6133|6144|615|100\*106',
                   '&', resub)
    # print(len(resub))
    resub = re.sub(r'[A-Za-z\!\%\[\]\,\。\#：]', '&', resub)
    # print(len(resub))
    resub = re.findall(r"\d+\.{0,1}\d{0,2}", resub)
    print(len(resub), resub)
    result = '&'.join(resub)
    print(len(result), result)
    return result


if __name__ == '__main__':
    shortcontent(
        r'上游水位：18.32m下游进水池水位：15.87m下游清污机前水位：15.91m瞬时流量：0.00m%s平均流速0.00m/s35kV进线开关柜Ia1.5AP90kQ1kVarcOSP1.00所变进线开关柜Ia1.5AP94Q4kVarcOSP1.00主变进线开关柜Ia1.0P0kQQkVarcOSY1.00母线电压Uab0.0kVUbc0.0kVUca0.0kVTMY-100*106kVI段母线电压Uab0.0kVUbc0.0kVUca0.0kV6016kV进线关柜0.0P0kQ0kVarCOS1.00631站变高压开关柜1a0.4AP0QQkVarCOS1.00621发电机Ia0.0P0.0kvQ0.0kVarUL0.0”IL0.0COS0.00622电动机130.0P0.0kvQ0.0kVarUL0.0IL0.0COS1.006111#机组1a0.0AP0.0kvQ0.0kVarUL0.00VIL0.00ACOS1.006122#机组la0.0AP0.0kvQ0.0kVarUL0.00VIL0.00ACOS1.006133#机组1a0.0AP0.0kvQ0.0kVarUL0.00IL0.00ACOS1.00中6144#机组Ia0.0A0.0kv0.0kVarUL0.00VIL0.00ACOS1.00615二站发电开关柜Ia0.1P0kwQ0kVarCOS中1.00'
    )
